﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyLib;
using Portal.Interface;
using System.Web.Security;
using Portal.Logic;

namespace WebPortal
{
    public partial class Logon : System.Web.UI.Page
    {
        IOrg _orgSrv = ServiceContainer.Instance().GetService<IOrg>();
        public string Login_UserOrPasswordInvalid = Resources.lang.Login_UserOrPasswordInvalid;
        public string Login_UserRequired = Resources.lang.Login_UserRequired;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                hidReturnUrl.Value = Request.QueryString["ReturnUrl"];
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string userName = txtUser.Text.Trim().ToUpper();
            string userPwd = txtPassword.Text.Trim();

            if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(userPwd))
            {
                TRXN_Logic Logic = new TRXN_Logic();
                if (!string.IsNullOrEmpty(Logic.GetLevelUser("USERNAME = '" + userName + "' AND USERPWD = '" + userPwd + "'")))
                {
                    HttpContext.Current.Session["UserEntity"] = null;//清除用户信息
                    HttpContext.Current.Session["userAccount"] = "ULTIMUS\\" + userName;
                    FormsAuthentication.SetAuthCookie("ULTIMUS\\" + userName, false);
                    if (!string.IsNullOrEmpty(hidReturnUrl.Value))
                    {
                        if (hidReturnUrl.Value.IndexOf("Default.aspx") < 0)
                        {
                            Response.Redirect("Default.aspx?ReturnUrl=" + hidReturnUrl.Value.Trim());
                        }
                        else
                        {
                            Response.Redirect("Default.aspx");
                        }
                    }
                    else
                    {
                        Response.Redirect("Default.aspx");
                    }
                }
            }
        }
    }
}